﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace SR.ExpressionEvaluator.Lib.Core.Functions
{
    public class And : IFunction
    {
        List<object> _Args = new List<object>();

        public System.Collections.Generic.List<object> Args
        {
            get
            {
                return _Args;
            }
            set
            {
                _Args = value;
            }
        }

        public object Evaluate()
        {
            if (!Validate())
            {
                throw new Exception("AND: Validation failed");
            }

            bool result = true;
            foreach (object arg in Args)
            {
                if (String.IsNullOrEmpty(arg.ToString()))
                {
                    continue;
                }
                result = result && Convert.ToBoolean(arg);
            }

            return result;
        }

        public bool Validate()
        {
            if (Args.Count == 0)
            {
                return false;
            }
            return true;
        }

        public string GetDefinition()
        {
            return @"AND(<cond1>,<cond2>,...)";
        }
    }
}
